﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Newtonsoft.Json;
using System.IO;

namespace DBETLTools
{
    public enum DBtype
    {
        Mysql
    }
    public enum DBCopyMode
    {
        InstUpdateDelTrigger,
        AddCopy,
        Del,
        Update,
        FullCpoy

    }
  public  enum FileldMode
    {
        Select,
        Full
    }
    public enum DBTRIGGER
    {
        INSERT, UPDATE, DELETE
    }
    public class DBConfig
    {
        private const string file = "./DBConfig.json";
        public DBtype dBtype;
        public DBCopyMode bCopyMode;
        public String DBSource;
        public String DBTarget;
        public List<DBTable> DBTables;
        public FileldMode fileldMode;
        public List<DBField> dBFields;
        public DBConfig()
            {
            dBtype = DBtype.Mysql;
            bCopyMode = DBCopyMode.InstUpdateDelTrigger;
            fileldMode = FileldMode.Full;
            }

        public static DBConfig Config { get {
                if (File.Exists(file))
                    return JsonConvert.DeserializeObject<DBConfig>(System.IO.File.ReadAllText(file));
                else 
                    return new DBConfig()  ;
            }    }

        internal static void SConfig(DBConfig loadConfig)
        {
             
                String json = JsonConvert.SerializeObject(loadConfig);
                System.IO.File.WriteAllText(file, json);
              
        }
    }
    public class DBTable
    {
        public String SourceName;
        public String TargetName;
        public DBTRIGGER[] dBTRIGGERs;
    }
    public class DBField
    {
        public String SourceName;
        public String TargetName;
    }
}
